package com.offcn.gateway.cors;

import com.offcn.gateway.filter.JwtCheckGatewayFilterFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class GatewayCorsConfig {


    @Bean
    public CorsWebFilter getCorsFilter(){
        UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedHeader("*");  //允许使用请求头跨域
        corsConfiguration.addAllowedMethod("*");    //允许使用请求方法跨域
        corsConfiguration.addAllowedOrigin("*");     //允许使用url地址跨域
        corsConfiguration.setAllowCredentials(true);    //允许使用cookie跨域
        urlBasedCorsConfigurationSource.registerCorsConfiguration("/**",corsConfiguration);
        return new CorsWebFilter(urlBasedCorsConfigurationSource);
    }

}
